//
//  PersonalHomePageArticleCell.m
//  OnionHome
//
//  Created by fengjie on 2019/9/27.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "PersonalHomePageArticleCell.h"

@interface PersonalHomePageArticleCell ()

/**用户视图*/
@property (nonatomic,strong)UserIconAndNameView*userView;
/**bottomView*/
@property (nonatomic,strong)ShareNewsPraiseView*bottomView;
/**左边文字*/
@property (nonatomic,strong)UILabel*leftLabel;
/**右边图片*/
@property (nonatomic,strong)UIImageView*rightImage;

/**<#属性#>*/
@property (nonatomic,strong)UIView*bgView;
/**<#属性#>*/
@property (nonatomic,strong)UIButton*seleBtn;
@end

@implementation PersonalHomePageArticleCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self createUI];
    }
    return self;
}

-(void)reloadCell:(BOOL)isRight{
    self.seleBtn.hidden = !isRight;
    CGFloat left = 0;
    if (isRight) {
        left = 40;
    }
    [self.bgView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(left);
    }];

}
-(void)setModel:(PersonalHomePageModel *)model{
    _model = model;
    self.userView.deleButton.hidden = model.isShare;
    self.userView.userName.text = model.userName;
    self.userView.iconImage.image = IMAGE_NAMED(model.userImage);
    [self.bottomView.shareBtn setTitle:model.zhuanfaNum forState:UIControlStateNormal];
    [self.bottomView.newsBtn setTitle:model.xiaoxiNum forState:UIControlStateNormal];
    [self.bottomView.praiseBtn setTitle:model.zanNum forState:UIControlStateNormal];
    self.bottomView.praiseBtn.selected = model.isZan;
    
//    self.leftLabel.text = model.contex;
    [TitleTool setDynamicTitle:model.contex Label:self.leftLabel];
    self.rightImage.image = IMAGE_NAMED(model.rightImage);
    self.seleBtn.selected = model.isSelecte;

}
-(void)createUI{
    
    
    self.seleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.seleBtn setBackgroundImage:IMAGE_NAMED(@"me_check_pay_type_defut") forState:UIControlStateNormal];
    [self.seleBtn setBackgroundImage:IMAGE_NAMED(@"delete_check_selecet") forState:UIControlStateSelected];
    self.seleBtn.hidden = YES;
    
    kWeakSelf(weakSelf);
    [self.seleBtn addActionHandler:^{
        weakSelf.seleBtn.selected = !weakSelf.seleBtn.selected;
    BlockSafeRun(weakSelf.selecteAction,weakSelf.seleBtn.selected);

    }];
    
    [self addSubview:self.seleBtn];
    
    [self.seleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(16);
    }];

    self.bgView = UIView.new;
    self.bgView.userInteractionEnabled = YES;
    
    [self addSubview:self.bgView];
    
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(0);
    }];
    
    [self.bgView addSubview:self.userView];
    [self.bgView addSubview:self.leftLabel];
    [self.bgView addSubview:self.rightImage];
    [self.bgView addSubview:self.bottomView];
    
    [self.userView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(0);
    }];
    [self.rightImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-16);
        make.top.mas_equalTo(self.userView.mas_bottom);
        make.width.mas_equalTo(112);
        make.height.mas_equalTo(84);
    }];
    [self.leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.top.bottom.mas_equalTo(self.rightImage);
        make.right.mas_equalTo(self.rightImage.mas_left).offset(-8);
    }];
    
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.mas_equalTo(0);
        make.top.mas_equalTo(self.rightImage.mas_bottom);
    }];
}
-(UserIconAndNameView*)userView{
    if(!_userView){
        _userView=[[UserIconAndNameView alloc] initWithFrame:CGRectZero];
        [_userView.deleButton setBackgroundImage:IMAGE_NAMED(@"sangedian") forState:UIControlStateNormal];
        
        [_userView.deleButton addActionHandler:^{
            
        }];
        _userView.dynamicData.text = @"美食达人";
        
    }
    return _userView;
}
-(ShareNewsPraiseView*)bottomView{
    if(!_bottomView){
        _bottomView=[[ShareNewsPraiseView alloc] initWithFrame:CGRectZero];
        [_bottomView.shareBtn setImage:IMAGE_NAMED(@"image_2") forState:UIControlStateNormal];

    }
    return _bottomView;
}
-(UILabel*)leftLabel{
    if(!_leftLabel){
        _leftLabel=[UILabel new];
        _leftLabel.textColor = UIColorFromRGB(0x273323);
        _leftLabel.font = SYSTEMFONT(18);
        _leftLabel.numberOfLines = 0;
        _leftLabel.text = @"做烤鸡的时候，千万别直接放进烤箱，多加一步，鸡肉更加入味";
    }
    return _leftLabel;
}
-(UIImageView*)rightImage{
    if(!_rightImage){
        _rightImage=[UIImageView new];
        _rightImage.image = IMAGE_NAMED(@"dynamicDefut");
    }
    return _rightImage;
}
@end
